package com.huayun.plugin.bk.controller;

import com.huayun.plugin.bk.calculate.QuarticEquationSolver;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/bk")
public class CalculateController {
    // http://127.0.0.1:8080/calculate?name=lisi
    @RequestMapping(value = "/calculate", method = RequestMethod.POST)
    @ResponseBody
    public List<Double> calculate(@RequestBody List<Double> nums) {
        System.out.println(nums);
        double a = nums.get(0), b = nums.get(1), c = nums.get(2), d = nums.get(3), e = nums.get(4);
//        double a = 4.583088, b = -0.650802, c = 2.7313, d = -0.31658, e = 0.009665;
        List<Double> roots = QuarticEquationSolver.solveQuartic(a, b, c, d, e);
        System.out.println("方程的根为：");
        for (double root : roots) {
            System.out.println(root);
        }
        return roots;
    }

//    @RequestMapping(value = "/transformMatrix", method = RequestMethod.POST)
//    @ResponseBody
//    public List<Double> transformMatrix(@RequestBody MatrixRequest request) {
//        double[] partStart = request.getPartStart();
//        double[] partEnd = request.getPartEnd();
//        double[] assemblyStart = request.getAssemblyStart();
//        double[] assemblyEnd = request.getAssemblyEnd();
//        return calculateTransformMatrix(partStart, partEnd, assemblyStart, assemblyEnd);
//    }
//
//    @RequestMapping(value = "/calculateNewPoint", method = RequestMethod.POST)
//    @ResponseBody
//    public double[] calculateNewPoint(@RequestBody PointRequest request) {
//
//        double[] onePoint= request.getOnePoint();
//        double[] twoPoint= request.getTwoPoint();
//        double[] threePoint= request.getThreePoint();
//        double distance= request.getDistance();
//
//        return LinePointCalculator.calculateNewPoint(onePoint, twoPoint, threePoint, distance);
//    }
//
//    @RequestMapping(value = "/calculateDistance", method = RequestMethod.POST)
//    @ResponseBody
//    public double calculateDistance(@RequestBody PointRequest request) {
//
//        double[] onePoint= request.getOnePoint();
//        double[] twoPoint= request.getTwoPoint();
////        double[] threePoint= request.getThreePoint();
////        double distance= request.getDistance();
//
//        return LinePointCalculator.calculateDistance(onePoint, twoPoint);
//    }
}